import 'package:flutter/material.dart';
import 'package:flutter_design/com/zerogis/flutterdesign/http/MemberService.dart';
import 'package:zpub_plugin/com/zerogis/zpubPlugin/widget/WidgetStatefulBase.dart';
import 'package:zpub_bas/zpub_bas.dart';

/*
 * 主页(框架用例) <br/>
 * 需要传入的键：<br/>
 * 传入的值类型： <br/>
 * 传入的值含义：<br/>
 * 是否必传 ：
 */
class HomeWidget1 extends WidgetStatefulBase {
  HomeWidget1({Key key, plugin}) : super(key: key, plugin: plugin);

  State<StatefulWidget> createState() {
    return new HomeWidgetState();
  }

  static String toStrings() {
    return "HomeWidget1";
  }
}

/*
 * 页面功能 <br/>
 */
class HomeWidgetState extends WidgetBaseState<HomeWidget1> {
  Widget build(BuildContext context) {
    var listTileHeight = 33.5;
    var listTileMargin = EdgeInsets.fromLTRB(3, 3, 3, 1);
    var listTileMarginBottom = EdgeInsets.fromLTRB(3, 3, 3, 10);
    return buildBody(
        context,
        new ListView(
            scrollDirection: Axis.vertical,
            padding: const EdgeInsets.fromLTRB(20, 8, 20, 8),
            children: <Widget>[
              new Container(
                height: listTileHeight,
                margin: listTileMarginBottom,
                child: new RaisedButton(
                  onPressed: () {
                    MemberService.loginByEmail("admin", "12345678", this);
                  },
                  child: new Text('请求网络数据'),
                  color: Theme.of(context).buttonColor,
                  shape: Border.all(
                      color: Colors.red, style: BorderStyle.solid, width: 1),
                ),
              ),
              new Container(
                height: listTileHeight,
                margin: listTileMargin,
                child: new RaisedButton(
                  onPressed: () {
                    setState(() {
                      mTitle = 'FlutterDesign~';
                    });
                  },
                  child: new Text('设置标题'),
                  color: Theme.of(context).buttonColor,
                  shape: Border.all(
                      color: Colors.green, style: BorderStyle.solid, width: 1),
                ),
              ),
              new Container(
                height: listTileHeight,
                margin: listTileMarginBottom,
                child: new RaisedButton(
                  onPressed: () {
                    setState(() {
                      mTitleBarBg = Colors.green;
                    });
                  },
                  child: new Text('设置标题栏背景'),
                  color: Theme.of(context).buttonColor,
                  shape: Border.all(
                      color: Colors.green, style: BorderStyle.solid, width: 1),
                ),
              ),
              new Container(
                height: listTileHeight,
                margin: listTileMargin,
                child: new RaisedButton(
                  onPressed: () {
                    setState(() {
                      setRightButtonFromAsset(
                          'assets/images/app_icon_default.png');
                    });
                  },
                  child: new Text('设置右边按钮(FromAsset)'),
                  color: Theme.of(context).buttonColor,
                  shape: Border.all(
                      color: Colors.blue, style: BorderStyle.solid, width: 1),
                ),
              ),
              new Container(
                height: listTileHeight,
                margin: listTileMargin,
                child: new RaisedButton(
                  onPressed: () {
                    setState(() {
                      setRightButtonFromIcon(Icons.menu);
                    });
                  },
                  child: new Text('设置右边按钮(FromIcon)'),
                  color: Theme.of(context).buttonColor,
                  shape: Border.all(
                      color: Colors.blue, style: BorderStyle.solid, width: 1),
                ),
              ),
              new Container(
                height: listTileHeight,
                margin: listTileMargin,
                child: new RaisedButton(
                  onPressed: () {
                    setState(() {
                      setRightButtonFromText('右边');
                    });
                  },
                  child: new Text('设置右边按钮(FromText)'),
                  color: Theme.of(context).buttonColor,
                  shape: Border.all(
                      color: Colors.blue, style: BorderStyle.solid, width: 1),
                ),
              ),
              new Container(
                height: listTileHeight,
                margin: listTileMarginBottom,
                child: new RaisedButton(
                  onPressed: () {
                    setState(() {
                      btn_right = null;
                    });
                  },
                  child: new Text('隐藏右边按钮'),
                  color: Theme.of(context).buttonColor,
                  shape: Border.all(
                      color: Colors.blue, style: BorderStyle.solid, width: 1),
                ),
              ),
              new Container(
                height: listTileHeight,
                margin: listTileMargin,
                child: new RaisedButton(
                  onPressed: () {
                    setState(() {
                      setBorderButtonFromAsset(
                          'assets/images/app_icon_default.png');
                    });
                  },
                  child: new Text('设置侧边按钮(FromAsset)'),
                  color: Theme.of(context).buttonColor,
                  shape: Border.all(
                      color: Colors.yellow, style: BorderStyle.solid, width: 1),
                ),
              ),
              new Container(
                height: listTileHeight,
                margin: listTileMargin,
                child: new RaisedButton(
                  onPressed: () {
                    setState(() {
                      setBorderButtonFromIcon(Icons.add);
                    });
                  },
                  child: new Text('设置侧边按钮(FromIcon)'),
                  color: Theme.of(context).buttonColor,
                  shape: Border.all(
                      color: Colors.yellow, style: BorderStyle.solid, width: 1),
                ),
              ),
              new Container(
                height: listTileHeight,
                margin: listTileMargin,
                child: new RaisedButton(
                  onPressed: () {
                    setState(() {
                      setBorderButtonFromText('侧边');
                    });
                  },
                  child: new Text('设置侧边按钮(FromText)'),
                  color: Theme.of(context).buttonColor,
                  shape: Border.all(
                      color: Colors.yellow, style: BorderStyle.solid, width: 1),
                ),
              ),
              new Container(
                height: listTileHeight,
                margin: listTileMarginBottom,
                child: new RaisedButton(
                  onPressed: () {
                    setState(() {
                      btn_border = null;
                    });
                  },
                  child: new Text('隐藏侧边按钮'),
                  color: Theme.of(context).buttonColor,
                  shape: Border.all(
                      color: Colors.yellow, style: BorderStyle.solid, width: 1),
                ),
              ),
              new Container(
                height: listTileHeight,
                margin: listTileMargin,
                child: new RaisedButton(
                  onPressed: () {
                    setState(() {
                      setLeadingButtonFromAsset(
                          'assets/images/app_icon_default.png');
                    });
                  },
                  child: new Text('设置左边按钮(FromAsset)'),
                  color: Theme.of(context).buttonColor,
                  shape: Border.all(
                      color: Colors.teal, style: BorderStyle.solid, width: 1),
                ),
              ),
              new Container(
                height: listTileHeight,
                margin: listTileMargin,
                child: new RaisedButton(
                  onPressed: () {
                    setState(() {
                      setLeadingButtonFromIcon(Icons.search);
                    });
                  },
                  child: new Text('设置左边按钮(FromIcon)'),
                  color: Theme.of(context).buttonColor,
                  shape: Border.all(
                      color: Colors.teal, style: BorderStyle.solid, width: 1),
                ),
              ),
              new Container(
                height: listTileHeight,
                margin: listTileMarginBottom,
                child: new RaisedButton(
                  onPressed: () {
                    setState(() {
                      mLeading = new Container(width: 0, height: 0);
                    });
                  },
                  child: new Text('隐藏左边按钮'),
                  color: Theme.of(context).buttonColor,
                  shape: Border.all(
                      color: Colors.teal, style: BorderStyle.solid, width: 1),
                ),
              ),
              new Container(
                height: listTileHeight,
                margin: listTileMargin,
                child: new RaisedButton(
                  onPressed: () {
                    showToast('Hello,FlutterDesign~');
                  },
                  child: new Text('showToast'),
                  color: Theme.of(context).buttonColor,
                  shape: Border.all(
                      color: Colors.cyan, style: BorderStyle.solid, width: 1),
                ),
              ),
              new Container(
                height: listTileHeight,
                margin: listTileMarginBottom,
                child: new RaisedButton(
                  onPressed: () {
                    showSnackBar('Hello,FlutterDesign~', label: 'continue');
                  },
                  child: new Text('showSnackBar'),
                  color: Theme.of(context).buttonColor,
                  shape: Border.all(
                      color: Colors.cyan, style: BorderStyle.solid, width: 1),
                ),
              ),
              new Container(
                height: listTileHeight,
                margin: listTileMargin,
                child: new RaisedButton(
                  onPressed: () {
                    setState(() {
                      showProgressBar();
                    });
                  },
                  child: new Text('显示网络进度栏'),
                  color: Theme.of(context).buttonColor,
                  shape: Border.all(
                      color: Colors.red, style: BorderStyle.solid, width: 1),
                ),
              ),
              new Container(
                height: listTileHeight,
                margin: listTileMarginBottom,
                child: new RaisedButton(
                  onPressed: () {
                    setState(() {
                      hideProgressBar();
                    });
                  },
                  child: new Text('隐藏网络进度栏'),
                  color: Theme.of(context).buttonColor,
                  shape: Border.all(
                      color: Colors.red, style: BorderStyle.solid, width: 1),
                ),
              ),

              new Container(
                height: listTileHeight,
                margin: listTileMarginBottom,
                child: new RaisedButton(
                  onPressed: () {
                    runPluginName('TestPlugin');
                  },
                  child: new Text('跳转到测试页面'),
                  color: Theme.of(context).buttonColor,
                  shape: Border.all(
                      color: Colors.red, style: BorderStyle.solid, width: 1),
                ),
              ),

            ]));
  }

  void onClick(Widget widget) {
    if (widget.key == key_btn_right) {
      showSnackBar('点击了右边按钮~');
    } else if (widget.key == key_btn_border) {
      showSnackBar('点击了侧边按钮~');
    } else if (widget.key == key_btn_leading) {
      showSnackBar('点击了左边按钮~');
    }
  }

  @override
  Future<void> onRefresh() {
    return super.onRefresh();
  }

  @override
  Future<void> loadMore() {
    return super.loadMore();
  }
}

/*
 * 类描述：首页组件提供的Service
 * 作者：郑朝军 on 2019/6/6
 * 邮箱：1250393285@qq.com
 * 公司：武汉智博创享科技有限公司
 * 修改人：郑朝军 on 2019/6/6
 * 修改备注：
 */
class HomeWidget1Service extends InterfaceBaseImpl {
  @override
  Widget runWidget({dynamic initPara}) {
    return new HomeWidget1();
  }
}
